set more off
clear all

cd "C:\Users\mhoro\Dropbox\CCES 2020\Civic Pulse\"

insheet using CivicPulse_Horowitz_2020_10.csv, comma

* Data Conversion

* Cars

replace vehicles1="2" if vehicles1=="A few times a year"
replace vehicles1="3" if vehicles1=="A few times a month"
replace vehicles1="4" if vehicles1=="A few times a week"
replace vehicles1="5" if vehicles1=="Almost every day or more"
replace vehicles1="0" if vehicles1=="I do not know what ridesharing apps are"
replace vehicles1="." if vehicles1=="NA"
replace vehicles1="1" if vehicles1=="Never"
destring vehicles1, replace
label var vehicles1 "Pre-COVID Rideshare App Usage"

replace vehicles2="1" if vehicles2=="Strongly support"
replace vehicles2="2" if vehicles2=="Somewhat support"
replace vehicles2="3" if vehicles2=="Neither support nor oppose"
replace vehicles2="4" if vehicles2=="Somewhat oppose"
replace vehicles2="5" if vehicles2=="Strongly oppose"
replace vehicles2="." if vehicles2=="NA"
destring vehicles2, replace
label var vehicles2 "Cars Support"

replace vehicles4="1" if vehicles4=="Not at all concerned"
replace vehicles4="2" if vehicles4=="Moderately concerned"
replace vehicles4="3" if vehicles4=="Slightly concerned"
replace vehicles4="4" if vehicles4=="Very concerned"
replace vehicles4="5" if vehicles4=="Extremely concerned"
replace vehicles4="." if vehicles4=="NA"
destring vehicles4, replace
label var vehicles4 "Cars Safety Concern"

replace vehicles5="1" if vehicles5=="Very likely"
replace vehicles5="2" if vehicles5=="Somewhat likely"
replace vehicles5="3" if vehicles5=="Neither more nor less likely"
replace vehicles5="4" if vehicles5=="Somewhat unlikely"
replace vehicles5="5" if vehicles5=="Very unlikely"
replace vehicles5="." if vehicles5=="NA"
destring vehicles5, replace
label var vehicles5 "Likeliness To Ride"

gen personalride=.
replace personalride=5 if vehicles5==1
replace personalride=4 if vehicles5==2
replace personalride=3 if vehicles5==3
replace personalride=2 if vehicles5==4
replace personalride=1 if vehicles5==5
label var personalride "Likeliness To Ride"


replace vehicles6="1" if vehicles6=="Much more supportive"
replace vehicles6="2" if vehicles6=="Somewhat more supportive"
replace vehicles6="3" if vehicles6=="Neither more nor less supportive"
replace vehicles6="4" if vehicles6=="Somewhat less supportive"
replace vehicles6="5" if vehicles6=="Much less supportive"
replace vehicles6="." if vehicles6=="NA"
destring vehicles6, replace
label var vehicles6 "Impact of COVID (Cars)"

* Surgery

replace hc1="1" if hc1=="Strongly support"
replace hc1="2" if hc1=="Somewhat support"
replace hc1="3" if hc1=="Neither support nor oppose"
replace hc1="4" if hc1=="Somewhat oppose"
replace hc1="5" if hc1=="Strongly oppose"
replace hc1="." if hc1=="NA"
destring hc1, replace
label var hc1 "Autonomous Surgery Support"

replace hc3="1" if hc3=="Not at all concerned"
replace hc3="2" if hc3=="Moderately concerned"
replace hc3="3" if hc3=="Slightly concerned"
replace hc3="4" if hc3=="Very concerned"
replace hc3="5" if hc3=="Extremely concerned"
replace hc3="." if hc3=="NA"
destring hc3, replace
label var hc3 "Surgery Safety Concern"

replace hc4="1" if hc4=="Strongly support"
replace hc4="2" if hc4=="Somewhat support"
replace hc4="3" if hc4=="Neither support nor oppose"
replace hc4="4" if hc4=="Somewhat oppose"
replace hc4="5" if hc4=="Strongly oppose"
replace hc4="." if hc4=="NA"
destring hc4, replace
label var hc4 "AI for HC Decisions"

replace hc5="1" if hc5=="Much more supportive"
replace hc5="2" if hc5=="Somewhat more supportive"
replace hc5="3" if hc5=="Neither more nor less supportive"
replace hc5="4" if hc5=="Somewhat less supportive"
replace hc5="5" if hc5=="Much less supportive"
replace hc5="." if hc5=="NA"
destring hc5, replace
label var hc5 "Impact of COVID (Surgery)"

* Use of AI

replace aigrid_1="4" if aigrid_1=="Very Supportive"
replace aigrid_1="3" if aigrid_1=="Somewhat Supportive"
replace aigrid_1="." if aigrid_1=="No Opinion"
replace aigrid_1="2" if aigrid_1=="Somewhat Unsupportive"
replace aigrid_1="1" if aigrid_1=="Very Unsupportive"
replace aigrid_1="." if aigrid_1=="NA"
destring aigrid_1, replace
label var aigrid_1 "Facial Recognition Surveillance"

replace aigrid_2="4" if aigrid_2=="Very Supportive"
replace aigrid_2="3" if aigrid_2=="Somewhat Supportive"
replace aigrid_2="." if aigrid_2=="No Opinion"
replace aigrid_2="2" if aigrid_2=="Somewhat Unsupportive"
replace aigrid_2="1" if aigrid_2=="Very Unsupportive"
replace aigrid_2="." if aigrid_2=="NA"
destring aigrid_2, replace
label var aigrid_2 "General Monitoring"

replace aigrid_3="4" if aigrid_3=="Very Supportive"
replace aigrid_3="3" if aigrid_3=="Somewhat Supportive"
replace aigrid_3="." if aigrid_3=="No Opinion"
replace aigrid_3="2" if aigrid_3=="Somewhat Unsupportive"
replace aigrid_3="1" if aigrid_3=="Very Unsupportive"
replace aigrid_3="." if aigrid_3=="NA"
destring aigrid_3, replace
label var aigrid_3 "State Jobs"

replace aigrid_4="4" if aigrid_4=="Very Supportive"
replace aigrid_4="3" if aigrid_4=="Somewhat Supportive"
replace aigrid_4="." if aigrid_4=="No Opinion"
replace aigrid_4="2" if aigrid_4=="Somewhat Unsupportive"
replace aigrid_4="1" if aigrid_4=="Very Unsupportive"
replace aigrid_4="." if aigrid_4=="NA"
destring aigrid_4, replace
label var aigrid_4 "Prison Sentences"

replace aigrid_5="4" if aigrid_5=="Very Supportive"
replace aigrid_5="3" if aigrid_5=="Somewhat Supportive"
replace aigrid_5="." if aigrid_5=="No Opinion"
replace aigrid_5="2" if aigrid_5=="Somewhat Unsupportive"
replace aigrid_5="1" if aigrid_5=="Very Unsupportive"
replace aigrid_5="." if aigrid_5=="NA"
destring aigrid_5, replace
label var aigrid_5 "Transplant List"

replace aigrid_6="4" if aigrid_6=="Very Supportive"
replace aigrid_6="3" if aigrid_6=="Somewhat Supportive"
replace aigrid_6="." if aigrid_6=="No Opinion"
replace aigrid_6="2" if aigrid_6=="Somewhat Unsupportive"
replace aigrid_6="1" if aigrid_6=="Very Unsupportive"
replace aigrid_6="." if aigrid_6=="NA"
destring aigrid_6, replace
label var aigrid_6 "Natural Disaster Impact Planning"

replace aigrid_7="4" if aigrid_7=="Very Supportive"
replace aigrid_7="3" if aigrid_7=="Somewhat Supportive"
replace aigrid_7="." if aigrid_7=="No Opinion"
replace aigrid_7="2" if aigrid_7=="Somewhat Unsupportive"
replace aigrid_7="1" if aigrid_7=="Very Unsupportive"
replace aigrid_7="." if aigrid_7=="NA"
destring aigrid_7, replace
label var aigrid_7 "Responding to 911 Calls"

replace aigrid_8="4" if aigrid_8=="Very Supportive"
replace aigrid_8="3" if aigrid_8=="Somewhat Supportive"
replace aigrid_8="." if aigrid_8=="No Opinion"
replace aigrid_8="2" if aigrid_8=="Somewhat Unsupportive"
replace aigrid_8="1" if aigrid_8=="Very Unsupportive"
replace aigrid_8="." if aigrid_8=="NA"
destring aigrid_8, replace
label var aigrid_8 "Military Surveillance"

replace aigrid_9="4" if aigrid_9=="Very Supportive"
replace aigrid_9="3" if aigrid_9=="Somewhat Supportive"
replace aigrid_9="." if aigrid_9=="No Opinion"
replace aigrid_9="2" if aigrid_9=="Somewhat Unsupportive"
replace aigrid_9="1" if aigrid_9=="Very Unsupportive"
replace aigrid_9="." if aigrid_9=="NA"
destring aigrid_9, replace
label var aigrid_9 "Use of Military Force"

* General

replace general1="-2" if general1=="Strongly support gaining information over the risk to privacy"
replace general1="-1" if general1=="Somewhat support gaining information over the risk to privacy"
replace general1="0" if general1=="Equally important"
replace general1="1" if general1=="Somewhat support protecting privacy over gaining information"
replace general1="2" if general1=="Strongly support protecting privacy over gaining information"
replace general1="." if general1=="NA"
destring general1, replace
label var general1 "Support Info Gathering Over Privacy"

replace general2="1" if general2=="Not at all concerned"
replace general2="2" if general2=="Moderately concerned"
replace general2="3" if general2=="Slightly concerned"
replace general2="4" if general2=="Very concerned"
replace general2="5" if general2=="Extremely concerned"
replace general2="." if general2=="NA"
destring general2, replace
label var general2 "Concern about Algorithmic Bias"

replace aihomework="0" if aihomework=="Neither"
replace aihomework="1" if aihomework=="At work"
replace aihomework="2" if aihomework=="At home"
replace aihomework="3" if aihomework=="At work and at home"
replace aihomework="." if aihomework=="NA"
destring aihomework, replace
label var aihomework "Use of AI at Home or Work (1)"

gen aihomework2=.
replace aihomework2=0 if aihomework==0
replace aihomework2=1 if aihomework==1
replace aihomework2=1 if aihomework==2
replace aihomework2=2 if aihomework==3
replace aihomework2=. if aihomework==.
destring aihomework2, replace
label var aihomework2 "Use of AI at Home or Work (2)"

replace aimusicmovies="0" if aimusicmovies=="No"
replace aimusicmovies="1" if aimusicmovies=="Yes"
replace aimusicmovies="." if aimusicmovies=="NA"
destring aimusicmovies, replace

* Demographics

gen age=.
replace age=14 if birth=="1931 - 1935"
replace age=13 if birth=="1936 - 1940"
replace age=12 if birth=="1941 - 1945"
replace age=11 if birth=="1946 - 1950"
replace age=10 if birth=="1951 - 1955"
replace age=9 if birth=="1956 - 1960"
replace age=8 if birth=="1961 - 1965"
replace age=7 if birth=="1966 - 1970"
replace age=6 if birth=="1971 - 1975"
replace age=5 if birth=="1976 - 1980"
replace age=4 if birth=="1981 - 1985"
replace age=3 if birth=="1986 - 1990"
replace age=2 if birth=="1991 - 1995"
replace age=1 if birth=="1996 - 2000"
replace age=. if birth=="NA"
label var age "Age"

gen age2=.
replace age2=7 if birth=="1931 - 1935"
replace age2=7 if birth=="1936 - 1940"
replace age2=6 if birth=="1941 - 1945"
replace age2=6 if birth=="1946 - 1950"
replace age2=5 if birth=="1951 - 1955"
replace age2=5 if birth=="1956 - 1960"
replace age2=4 if birth=="1961 - 1965"
replace age2=4 if birth=="1966 - 1970"
replace age2=3 if birth=="1971 - 1975"
replace age2=3 if birth=="1976 - 1980"
replace age2=2 if birth=="1981 - 1985"
replace age2=2 if birth=="1986 - 1990"
replace age2=1 if birth=="1991 - 1995"
replace age2=1 if birth=="1996 - 2000"
replace age2=. if birth=="NA"
label var age2 "Age2"

replace sex="0" if sex=="Male"
replace sex="1" if sex=="Female"
replace sex="." if sex=="NA"
destring sex, replace
label var sex "Female"

gen education2=education
replace education2="." if education2=="NA"
replace education2="1" if education2=="Less than high school"
replace education2="2" if education2=="High school graduate"
replace education2="3" if education2=="Technical/trade school"
replace education2="4" if education2=="Some college"
replace education2="5" if education2=="College graduate"
replace education2="6" if education2=="Some graduate school"
replace education2="7" if education2=="Graduate degree"
destring education2, replace
label var education2 "Education: 1 = No HS, 7 = Grad Degree"

replace white_non_hispanic="." if white_non_hispanic=="NA"
destring white_non_hispanic, replace

replace gov_exp="." if gov_exp=="NA"
destring gov_exp, replace
label var gov_exp "Years of Government Experience"

replace electoral_compete="." if electoral_compete=="NA"
replace electoral_compete="." if electoral_compete=="Other"
replace electoral_compete="0" if electoral_compete=="No"
replace electoral_compete="1" if electoral_compete=="Yes"
destring electoral_compete, replace
label var electoral_compete "Opponent in General Election"

gen ambition2=.
replace ambition2=. if ambition=="NA"
replace ambition2=0 if ambition=="I am not considering future elected office."
replace ambition2=1 if ambition=="I am currently running for reelection."
replace ambition2=2 if ambition=="I am considering future elected office."
replace ambition2=3 if ambition=="I am currently running for a higher elected office."
order ambition2, after(ambition)

replace professionalization="." if professionalization=="NA"
replace professionalization="." if professionalization=="Other"
replace professionalization="0" if professionalization=="No salary"
replace professionalization="1" if professionalization=="Part-time salary"
replace professionalization="2" if professionalization=="Full-time salary"
destring professionalization, replace

gen ideology2=.
replace ideology2=. if ideology=="NA"
replace ideology2=. if ideology=="Not sure"
replace ideology2=1 if ideology=="Very liberal"
replace ideology2=2 if ideology=="Somewhat liberal"
replace ideology2=3 if ideology=="Moderate, middle of the road"
replace ideology2=4 if ideology=="Somewhat conservative"
replace ideology2=5 if ideology=="Very conservative"
label var ideology "Ideology"
order ideology2, after(ideology)

gen pid2=.
replace pid2=. if pid=="NA"
replace pid2=. if pid=="Other party (please specify):"
replace pid2=1 if pid=="Democrat"
replace pid2=2 if pid=="Independent"
replace pid2=3 if pid=="Republican"
label var pid2 "Party ID: 1 Dem 2 Indep 3 GOP"
order pid2, after(pid)

gen pid3=pid2
replace pid3=. if pid2==2
replace pid3=2 if pid_lean=="Neither"
replace pid3=1 if pid_lean=="Democratic Party"
replace pid3=3 if pid_lean=="Republican Party"
label var pid3 "Party ID: 1=Dem, 2=Ind, 3=GOP"
order pid3, after(pid2)

replace state_code="." if state_code=="NA"
destring state_code, replace

replace population_median="." if population_median=="NA"
destring population_median, replace

replace votes2016_per_gop="." if votes2016_per_gop=="NA"
destring votes2016_per_gop, replace

replace weight_2="." if weight_2=="NA"
destring weight_2, replace
label var weight_1 "All respondents"
label var weight_2 "Completed respondents"

gen urban_prop2=.
replace urban_prop2=0 if urban_prop=="[,0.012]"
replace urban_prop2=1 if urban_prop=="[0.12,0.96]"
replace urban_prop2=2 if urban_prop=="[0.96,]"
label var urban_prop2 "Urban Population"

gen college_prop2=.
replace college_prop2=0 if college_prop=="[,0.17]"
replace college_prop2=1 if college_prop=="[0.17,0.27]"
replace college_prop2=2 if college_prop=="[0.27,]"
label var college_prop2 "College Educated Population"

gen unemployment2=.
replace unemployment2=0 if unemployment=="[,0.044]"
replace unemployment2=1 if unemployment=="[0.044,0.068]"
replace unemployment2=2 if unemployment=="[0.068,]"
label var unemployment2 "Unemployment Rate"

gen carsupport=.
replace carsupport=1 if vehicles2==5
replace carsupport=2 if vehicles2==4
replace carsupport=3 if vehicles2==3
replace carsupport=4 if vehicles2==2
replace carsupport=5 if vehicles2==1
label var carsupport "Support for Self Driving Cars"

gen hcsupport=.
replace hcsupport=1 if hc1==5
replace hcsupport=2 if hc1==4
replace hcsupport=3 if hc1==3
replace hcsupport=4 if hc1==2
replace hcsupport=5 if hc1==1
label var hcsupport "Support for Autonomous Surgery"

gen autoindustry=0
replace autoindustry=1 if (state_abb=="MI" | state_abb=="MS" |state_abb=="AL" | state_abb=="KY" | state_abb=="MO" | state_abb=="TN" | state_abb=="IL" | state_abb=="TX" | state_abb=="IN" | state_abb=="OH")
replace autoindustry=. if state_abb=="."
label var autoindustry "Top 10 Auto Manufacturing State"
* https://www.mlive.com/auto/2015/03/these_are_the_top_10_states_fo.html

gen hcindustry=0
replace hcindustry=1 if (state_abb=="UT" | state_abb=="NV" |state_abb=="CA" | state_abb=="VA" | state_abb=="OR" | state_abb=="HI" | state_abb=="AZ" | state_abb=="TX" | state_abb=="AR" | state_abb=="GA")
label var hcindustry "Top 10 HC Employment State"

gen hcindustry2=.
replace hcindustry2=73 if (state_abb=="UT" | state_abb=="NV")
replace hcindustry2=68 if state_abb=="CA"
replace hcindustry2=65 if state_abb=="VA"
replace hcindustry2=63 if (state_abb=="OR" | state_abb=="HI" | state_abb=="AZ")
replace hcindustry2=62 if state_abb=="TX"
replace hcindustry2=58 if (state_abb=="AR" | state_abb=="GA") 
replace hcindustry2=57 if state_abb=="SC"
replace hcindustry2=56 if (state_abb=="WA" | state_abb=="FL") 
replace hcindustry2=55 if (state_abb=="CO" | state_abb=="ID") 
replace hcindustry2=54 if (state_abb=="NM" | state_abb=="NJ" | state_abb=="CT" | state_abb=="OK") 
replace hcindustry2=52 if (state_abb=="IA" | state_abb=="MD") 
replace hcindustry2=50 if state_abb=="AL"
replace hcindustry2=49 if state_abb=="KY"
replace hcindustry2=48 if (state_abb=="AK" | state_abb=="NE" | state_abb=="NC" | state_abb=="MS")
replace hcindustry2=47 if (state_abb=="WY" | state_abb=="IL") 
replace hcindustry2=46 if state_abb=="TN"
replace hcindustry2=45 if state_abb=="WI"
replace hcindustry2=44 if (state_abb=="LA" | state_abb=="NH" | state_abb=="PA" | state_abb=="MI" | state_abb=="IN")
replace hcindustry2=43 if state_abb=="MN"
replace hcindustry2=42 if (state_abb=="NY" | state_abb=="RI") 
replace hcindustry2=40 if (state_abb=="MT" | state_abb=="VT") 
replace hcindustry2=39 if (state_abb=="KS" | state_abb=="OH") 
replace hcindustry2=38 if state_abb=="ME"
replace hcindustry2=36 if (state_abb=="MO" | state_abb=="DE") 
replace hcindustry2=34 if state_abb=="WV"
replace hcindustry2=33 if state_abb=="MA"
replace hcindustry2=31 if state_abb=="ND"
replace hcindustry2=29 if state_abb=="SD"
replace hcindustry2=24 if state_abb=="DC"
label var hcindustry2 "Health Care Employment By State"
* https://www.bls.gov/opub/ted/2020/number-of-hospitals-and-hospital-employment-in-each-state-in-2019.htm

gen aiinfo=aihomework2+aimusicmovies
label var aiinfo "Self-Reported AI Use"

label var white_non_hispanic "White"

gen ai_grid_complete=.
replace ai_grid_complete=1 if aigrid_1!=. & aigrid_2!=. & aigrid_3!=. & aigrid_4!=. & aigrid_5!=. & aigrid_6!=. & aigrid_7!=. & aigrid_8!=. & aigrid_9!=.
gen gap = carsupport-personalride
gen standardgap=gap
replace standardgap=3 if gap==-3
replace standardgap=2 if gap==-2
replace standardgap=1 if gap==-1
bysort state_code: egen stategapmean = mean(gap)
bysort state_code: egen stategapmean2 = mean(standardgap)

* replace aiprior=. if aiprior=="NA"
* destring aiprior, replace

* gen ai_grid_complete=.
* replace ai_grid_complete=1 if aigrid_1!=. & aigrid_2!=. & aigrid_3!=. & aigrid_4!=. & aigrid_5!=. & aigrid_6!=. & aigrid_7!=. & aigrid_8!=. & aigrid_9!=.
* gen gap = vehicles2-vehicles5
* bysort state_code: egen stategapmean = mean(gap)

save civic_pulse_processed_for_stata.dta, replace

drop urban_prop college_prop unemployment
 
save civic_pulse_processed_for_R_final.dta, replace
outsheet using civic_pulse_processed_v2.csv, comma replace
